<?php
define('ROOT_URI', 'http://localhost/werk/phphulp.nl/ubbbar/Scripts');

function remote_listFiles()
{
	$files = array()
	foreach(glob('*') as $file) {
		$files[] = array(
			'id' 		=> md5($file),
			'thumbnail'	=> ROOT_URI . '/' . basename($file),
			'url'		=> ROOT_URI . '/' . basename($file),
			'mtime'		=> file_mtime($file)
		);
	}
	
	usort($files, 'sortOnMTime');
}

function sortOnMTime($a, $b) {
	if($a['mtime'] == $b['mtime'])		return 0;
	elseif($a['mtime'] > $b['mtime'])	return 1;
	else								return -1;
}

if(!isset($_GET['arguments'])) {
	$_GET['arguments'] = array();
}

if(isset($_GET['method')) {
	echo json_encode(call_user_func_array('remote_' . $_GET['method'], $_GET['arguments']));
}

?>